/*
 * CS_DUNGEON_MOB_VARIATION.cpp
 *
 *  Created on: 2013. 8. 27.
 *      Author: mega@gamevil.com
 */

#include "../../Command.h"
#include "../../User.h"
#include "../../NLogic/Static.h"
#include "../../NResource/Static.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_DUNGEON_MOB_VARIATION(User * pUser, ::Network::Packet * pPacket)
{
	/*
	 * /// 몹가중치(HP, 이동속도, 공격력, 방어력 ) 100% 기준
		CS_DUNGEON_MOB_VARIATION	0x083B
		{
			s8		s8Difficult;			//난이도 (0: 노멀, 1: 하드, 2: 헬)
		}

		SC_DUNGEON_MOB_VARIATION	0x083C
		{
			s16 s16ack;
			u8 u8normal_speed_add;
			u16 u16normal_attack_percent_rate;
			u16 u16normal_defence_percent_rate;

			u8 u8legend_speed_add;
			u16 u16legend_attack_percent_rate;
			u16 u16legend_defence_percent_rate;

			u8 u8boss_speed_add;
			u16 u16boss_attack_percent_rate;
			u16 u16boss_defence_percent_rate;
		}

	 */

	STRESSLOG("CS_DUNGEON_MOB_VARIATION");

	PREPARE_PACKET;

	NLogic::Space * pSpace = pUser->GetSpace();
	if (NULL == pSpace)
	{
		DEBUGLOG("CS_DUNGEON_MOB_VARIATION : pSpace is NULL");
		return;
	}

	if (false == pSpace->IsDungeon())
	{
		DEBUGLOG("CS_DUNGEON_MOB_VARIATION space is not single or party dungeion");
		return;
	}

	NResource::BalanceData * pBalance = NResource::Static::InstancePtr()->GetBalance()->GetBalancePtr(pUser);
	if (NULL == pBalance)
	{
		DEBUGLOG("CS_DUNGEON_MOB_VARIATION : pBalance is NULL!");
		return;
	}

	NResource::MonsterResource::Flyweight * pFly = NResource::Static::InstancePtr()->GetMonsterResource()->GetFly(pSpace->GetData()._table_id);
	if (NULL == pFly)
	{
		DEBUGLOG("CS_DUNGEON_MOB_VARIATION : pFly is NULL!", __FUNCTION__);
		return;
	}

	int dungeonMode = 0;
	pPacket->ParseMsg("%c", & dungeonMode);

	int moveSpeed = 0;
	int attackAdd = 100;
	int defenceAdd = 100;

	// 던전 난이도별 Variation
	switch (dungeonMode)
	{
	case 0:
		moveSpeed = pBalance->GetValue(EM_NORMAL_MOB_MOVING_SPEED_CONST);
		//attackAdd = (attackAdd * pBalance->GetValue(EM_NORMAL_MOB_ATT_CONST)) / 100;
		attackAdd = pFly->_NORMAL_ATT_CONST;
		defenceAdd = (defenceAdd * pBalance->GetValue(EM_NORMAL_MOB_DEF_CONST)) / 100;
		break;
	case 1:
		moveSpeed = pBalance->GetValue(EM_HARD_MOB_MOVING_SPEED_CONST);
		//attackAdd = (attackAdd * pBalance->GetValue(EM_HARD_MOB_ATT_CONST)) / 100;
		attackAdd = pFly->_HARD_ATT_CONST;
		defenceAdd = (defenceAdd * pBalance->GetValue(EM_HARD_MOB_DEF_CONST)) / 100;
		break;
	case 2:
		moveSpeed = pBalance->GetValue(EM_HELL_MOB_MOVING_SPEED_CONST);
		//attackAdd = (attackAdd * pBalance->GetValue(EM_HELL_MOB_ATT_CONST)) / 100;
		attackAdd = pFly->_HELL_ATT_CONST;
		defenceAdd = (defenceAdd * pBalance->GetValue(EM_HELL_MOB_DEF_CONST)) / 100;
		break;
	}

	// 레전드 몬스터 Variation
	// 공격값만 가중치 부여
	int legendMoveSpeed = moveSpeed;
	int legendDefenceAdd = defenceAdd;
	//int legendAttackAdd = (attackAdd * pBalance->GetValue(EM_LEGEND_ADD_ATTACK)) / 100;
	int legendAttackAdd = (attackAdd * pFly->_LEGEND_ATT_CONST) / 100;

	// 보스 몬스터 Variation
	// 던전별 보스에 따라 공격값만 가중치 부여
	int bossMoveSpeed = moveSpeed;
	int bossDefenceAdd = defenceAdd;
	int bossAttackAdd = (attackAdd * pFly->_BOSS_ATT_CONST) / 100;
//	int bossAttackAdd = attackAdd;

//	switch (pSpace->GetData()._table_id)
//	{
//	case 1 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS1)) / 100; break;
//	case 2 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS2)) / 100; break;
//	case 3 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS3)) / 100; break;
//	case 4 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS4)) / 100; break;
//	case 5 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS5)) / 100; break;
//	case 6 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS6)) / 100; break;
//	case 7 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS7)) / 100; break;
//	case 8 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS8)) / 100; break;
//	case 9 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS9)) / 100; break;
//	case 10 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS10)) / 100; break;
//	case 11 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS11)) / 100; break;
//	case 12 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS12)) / 100; break;
//	case 13 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS13)) / 100; break;
//	case 14 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS14)) / 100; break;
//	case 15 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS15)) / 100; break;
//	case 16 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS16)) / 100; break;
//	case 17 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS17)) / 100; break;
//	case 18 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS18)) / 100; break;
//	case 19 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS19)) / 100; break;
//	case 20 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS20)) / 100; break;
//	case 21 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS21)) / 100; break;
//	case 22 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS22)) / 100; break;
//	case 23 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS23)) / 100; break;
//	case 24 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS24)) / 100; break;
//	case 25 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS25)) / 100; break;
//	case 26 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS26)) / 100; break;
//	case 27 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS27)) / 100; break;
//	case 28 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS28)) / 100; break;
//	case 29 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS29)) / 100; break;
//	case 30 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS30)) / 100; break;
//	case 31 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS31)) / 100; break;
//	case 32 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS32)) / 100; break;
//	case 33 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS33)) / 100; break;
//	case 34 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS34)) / 100; break;
//	case 35 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS35)) / 100; break;
//	case 36 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS36)) / 100; break;
//	case 37 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS37)) / 100; break;
//	case 38 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS38)) / 100; break;
//	case 39 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS39)) / 100; break;
//	case 40 : bossAttackAdd = (bossAttackAdd * pBalance->GetValue(EM_ATT_CONST_BOSS40)) / 100; break;
//	}

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();

	pAck->MsgCat("%2d", ACK_OK);
	pAck->MsgCat("%c", moveSpeed);
	pAck->MsgCat("%2d", attackAdd);
	pAck->MsgCat("%2d", defenceAdd);

	pAck->MsgCat("%c", legendMoveSpeed);
	pAck->MsgCat("%2d", legendAttackAdd);
	pAck->MsgCat("%2d", legendDefenceAdd);

	pAck->MsgCat("%c", bossMoveSpeed);
	pAck->MsgCat("%2d", bossAttackAdd);
	pAck->MsgCat("%2d", bossDefenceAdd);
	pAck->MakePacket(CMD_SC_DUNGEON_MOB_VARIATION);

	pUser->Send(pAck);

	DEBUGLOG("CS_DUNGEON_MOB_VARIATION : move=%d, att=%d, def=%d, boss_move=%d, boss_att=%d, boss_def=%d",
			moveSpeed, attackAdd, defenceAdd, bossMoveSpeed, bossAttackAdd, bossDefenceAdd);
}

} /*NCommand*/ } /*ProjectZ*/
